﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Collections.Generic;

/// <summary>
/// Summary description for MyList
/// </summary>
public class MyList : List<CartItem>//danh sách chỉ chứa cart
{
    public MyList()
    {
    }
    public void AddToCart(CartItem item)
    {
        if (this.Contains(item))
        {
            foreach (CartItem cartItem in this)
            {
                if (cartItem.Equals(item))
                    cartItem.SoLuong++;
            }
        }
        else
        {
            this.Add(item);
        }
    }
    public void UpdateCart(CartItem item, int SL)
    {
        if (SL < 0)
            return;
        if (this.Contains(item))
        {
            foreach (CartItem cartItem in this)
            {
                if (cartItem.Equals(item))
                    cartItem.SoLuong += SL;
            }
        }
    }
    public void RemoveCart(CartItem item)
    {
        foreach (CartItem cartItem in this)
        {
            if (cartItem.Equals(item))
                this.Remove(cartItem);
        }
    }
    public decimal TongCart()
    {
        decimal Tong = 0;
        foreach (CartItem item in this)
        {
            Tong = Tong + item.Gia * item.SoLuong;
        }
        return Tong;
    }
}